//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.
// 			VisualNovelToolkit		     /_/_/_/_/_/_/_/_/_/.
// Copyright ©2013 - Sol-tribe.	/_/_/_/_/_/_/_/_/_/.
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using ViNoToolkit;

/// <summary>
/// ViNo EventManager. TriggerEvent will send message to EventReceiver GameObject.
/// </summary>
public class ViNoEventManager : MonoBehaviour {
	#region Public
	
	/// <summary>
	/// The event receiver.
	/// </summary>
	public GameObject eventReceiver;

	#endregion

	static private ViNoEventManager m_Instance;
	public static ViNoEventManager Instance {
		get {	return ViNoEventManager.m_Instance;	}
	}

		#region PublicMethods

	public void TriggerEvent( string evttype ){
		if( IsEvtReceiverAttach( ) ){
		 	eventReceiver.SendMessage( evttype , SendMessageOptions.DontRequireReceiver );			
		}
	}

	public void TriggerEvent( string evttype , string sendmessage ){
		if( IsEvtReceiverAttach( ) ){
		 	eventReceiver.SendMessage( evttype , sendmessage ,  SendMessageOptions.DontRequireReceiver );							
		}
	}

	public void TriggerEvent( string evttype , Hashtable args ){
		if( IsEvtReceiverAttach( ) ){
		 	eventReceiver.SendMessage( evttype , args , SendMessageOptions.DontRequireReceiver );							
		}
	}
	
	public void TriggerEvent( string evttype , ViNoEventData evtdata ){
		if( IsEvtReceiverAttach( ) ){
		 	eventReceiver.SendMessage( evttype , evtdata ,  SendMessageOptions.DontRequireReceiver );							
		}
	}

	public bool IsEvtReceiverAttach( ){
		if( eventReceiver == null ){
				ViNoDebugger.LogWarning( "ViNoEventManager eventReceiver Not Attached." );
				return false;
		}
		else{
				return true;
		}
	}

		#endregion

	void Awake(){
		m_Instance=  this;	
		
		DontDestroyOnLoad( gameObject );

		MessageEvent msgEvt = gameObject.GetComponent<MessageEvent>();
		if( msgEvt == null ){
			gameObject.AddComponent<MessageEvent>();
		}
	}


}
